<?php
return [
    'module' => [
        'name' => 'order',
        'title' => '订单',
        'table' => 'orders',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '订单ID',
            'unsigned' => true,
            'nullable' => false,
            'primary' => true,
            'auto_increment' => true,
            'required' => true,
        ],
        'order_no' => [
            'type' => 'varchar', 
            'length' => 64,
            'comment' => '订单编号',
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'user_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '用户ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'total_amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '订单总金额',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'pay_amount' => [
            'type' => 'decimal',
            'length' => '10,2', 
            'comment' => '实付金额',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'discount_amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '优惠金额',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'status' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '订单状态：0待付款，1已付款待发货，2已发货待收货，3已完成，4已取消，5已退款',
            'nullable' => false,
            'required' => true,
            'default' => 0,
            'index' => true,
        ],
        'pay_status' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '支付状态：0未支付，1支付中，2已支付，3退款中，4已退款',
            'nullable' => false,
            'required' => true,
            'default' => 0,
        ],
        'pay_time' => [
            'type' => 'timestamp',
            'comment' => '支付时间',
            'nullable' => true,
        ],
        'pay_type' => [
            'type' => 'varchar',
            'length' => 32,
            'comment' => '支付方式：wechat微信，alipay支付宝',
            'nullable' => false,
            'default' => '',
        ],
        'trade_no' => [
            'type' => 'varchar',
            'length' => 64,
            'comment' => '支付平台交易号',
            'nullable' => false,
            'default' => '',
        ],
        'shipping_name' => [
            'type' => 'varchar',
            'length' => 32,
            'comment' => '收货人姓名',
            'nullable' => false,
            'required' => true,
        ],
        'shipping_phone' => [
            'type' => 'varchar',
            'length' => 32,
            'comment' => '收货人电话',
            'nullable' => false,
            'required' => true,
        ],
        'shipping_address' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '收货地址',
            'nullable' => false,
            'required' => true,
        ],
        'shipping_time' => [
            'type' => 'timestamp',
            'comment' => '发货时间',
            'nullable' => true,
        ],
        'shipping_company' => [
            'type' => 'varchar',
            'length' => 64,
            'comment' => '快递公司',
            'nullable' => false,
            'default' => '',
        ],
        'shipping_no' => [
            'type' => 'varchar',
            'length' => 64,
            'comment' => '快递单号',
            'nullable' => false,
            'default' => '',
        ],
        'remark' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '订单备注',
            'nullable' => false,
            'default' => '',
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => true,
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => true,
        ],
        'refund_status' => [
            'type' => 'tinyint',
            'length' => 4,
            'comment' => '退款状态：0未退款，1退款中，2退款成功，3退款失败',
            'nullable' => false,
            'default' => 0,
            'index' => true,
        ],
        'refund_amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '退款金额',
            'nullable' => false,
            'default' => 0.00,
        ],
        'refund_reason' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '退款原因',
            'nullable' => false,
            'default' => '',
        ],
        'refund_time' => [
            'type' => 'timestamp',
            'comment' => '退款时间',
            'nullable' => true,
        ],
        'refund_trade_no' => [
            'type' => 'varchar',
            'length' => 64,
            'comment' => '退款交易号',
            'nullable' => false,
            'default' => '',
        ],
        'coupon_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '优惠券ID',
            'unsigned' => true,
            'nullable' => false,
            'default' => 0,
        ],
        'coupon_amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '优惠券抵扣金额',
            'nullable' => false,
            'default' => 0.00,
        ],
    ],
    
    'relations' => [
        'items' => [
            'type' => 'hasMany',
            'model' => 'OrderItem',
            'foreign_key' => 'order_id',
        ],
        'user' => [
            'type' => 'belongsTo',
            'model' => 'User',
            'foreign_key' => 'user_id',
        ],
        'refunds' => [
            'type' => 'hasMany',
            'model' => 'OrderRefund',
            'foreign_key' => 'order_id',
        ],
        'coupon' => [
            'type' => 'belongsTo',
            'model' => 'Coupon',
            'foreign_key' => 'coupon_id',
        ],
    ],
    
    'queries' => [
        'order_no' => ['like', '%?%'],
        'user_id' => ['=', '?'],
        'status' => ['=', '?'],
        'pay_status' => ['=', '?'],
        'refund_status' => ['=', '?'],
        'shipping_phone' => ['like', '%?%'],
        'created_at' => ['between', '?,?'],
        'refund_time' => ['between', '?,?'],
        'coupon_id' => ['=', '?'],
    ],
];